package com.qzimp.fujiancuo.mapper;

import com.mybatisflex.core.BaseMapper;
import com.qzimp.fujiancuo.entity.Cuo;
import com.qzimp.fujiancuo.entity.dto.CuoDetailsDto;
import com.qzimp.fujiancuo.entity.dto.CuoEventDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 *  映射层。
 *
 * @author 吴宗波
 * @since 2024-11-21
 */
public interface CuoMapper extends BaseMapper<Cuo> {

    /*根据厝id查询厝的所有事件*/
    CuoEventDTO getCuoEventId(Integer id);
     @Select(
            "SELECT " +
                    "    c.id AS cuoId, " +
                    "    c.name AS cuoName, " +
                    "    c.address AS cuoAddress, " +
                    "    c.description AS cuoDescription, " +
                    "    c.images AS cuoImages, " +
                    "    a.name AS architectureName, " +
                    "    a.architecture_style AS architectureStyle, " +
                    "    a.description AS architectureDescription, " +
                    "    a.images AS architectureImages, " +
                    "    a.category AS architectureCategory, " +
                    "    e.name AS eventName, " +
                    "    e.happen_time AS eventHappenTime, " +
                    "    e.description AS eventDescription, " +
                    "    l.name AS legendName, " +
                    "    l.description AS legendDescription, " +
                    "    l.personages AS legendPersonages " +
                    "FROM " +
                    "    tb_cuo c " +
                    "LEFT JOIN " +
                    "    tb_architecture a ON c.id = a.cuo_id " +
                    "LEFT JOIN " +
                    "    tb_event e ON c.id = e.cuo_id " +
                    "LEFT JOIN " +
                    "    tb_legend l ON c.id = l.cuo_id " +
                    "WHERE " +
                    "    c.id = #{cuoId}"
    )
     CuoDetailsDto getCuoDetailsByCuoId(@Param("cuoId") Integer cuoId);
}
